package com.gzq.administrator.testthread;


import android.app.Activity;
import android.os.Handler;
import android.os.Message;

import java.lang.ref.WeakReference;

/**
 * Created by gzq on 2018/2/11.
 */

public class HandlerHelper<T> extends Handler {
    private WeakReference<T> reference;

    public HandlerHelper(T context) {
        this.reference = new WeakReference<>(context);
    }

    @Override
    public void handleMessage(Message msg) {
        if (handlerResult != null)
            handlerResult.handleMessage(msg, reference.get());
    }

    private HandlerResult handlerResult;

    public void setOnHandlerResult(HandlerResult handlerResult) {
        this.handlerResult = handlerResult;
    }

    protected interface HandlerResult<T> {
        void handleMessage(Message msg, T self);
    }
}
